﻿using System;
using System.Threading.Tasks;

namespace RockBus.MessageRepository.Interfaces
{
    public interface IMessageRepository
    {   
        long CreateMessage(
            string correlationId,
            string messageVersion,
            string action,
            DateTime receiveTime,
            string receiveAddress);

        long CreateMessageFragment(
            long messageId,
            int partIndex,
            byte[] body,
            int size);

        void CompleteMessage(
            long messageId,
            int partCount,
            int size);

        long EnqueueEntry(
            long messageId,
            byte[] routingHeaderByteArray,
            int priority,
            bool orderedDelivery,
            string receiverMachineName,
            int receiverProcessId,
            int receiverAppDomainId,
            long? validityDurationSecs,
            long deliveryAttemptIntervalSecs,
            int maxDeliveryAttemptCount,
            bool isResponse);

        Task<DequeueResult> StartDequeueEnties(
            int maxEntryCount,
            string machineName,
            int processId,
            int appDomainId,
            string processorId);

        byte[] GetMessageFragment(long messageId, int partIndex);

        void CompleteEntry(long queueEntryId);

        void RollbackEntry(long queueEntryId, Exception exception);

        void FaultEntry(long queueEntryId, Exception exception);

        void CreateErrorMessage(
            long messageId,
            byte[] routingHeaderByteArray,
            string machineName,
            int processId,
            int appDomainId,
            int deliveryAttemptCount,
            Exception exception);
    }
}